home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / ead / ead27.dms / ead27.adf / Listati / NewEx.asm / NewEx.asm
Assembly Source File  |  1990-12-25  |  15KB  |  342 lines

  1. ***************************************************************
  2. *                                                             *
  3. * Programma ...... NewEx. asm                                 *
  4. *                                                             *
  5. * Autore ......... Kjell Cederfeldt                           *
  6. *                                                             *
  7. * Versione ....... 1.00, 11 giugno 1990                       *
  8. *                                                             *
  9. * Funzione ....... Esecutore di programmi Shell da Workbench  *
  10. *                                                             *
  11. ***************************************************************
  12.  
  13. ExecBase           = 4
  14. OpenLibrary        = -408  ; exec offset OpenLibrary(libName,version)(A1,D0)
  15. CloseLibrary       = -414  ; exec offset CloseLibrary(library)(a1)
  16. FindTask           = -294  ; exec offset FindTask(name)(a1)
  17. WaitPort           = -384  ; exec offset WaitPort(port)(a0)
  18. GetMsg             = -372  ; exec offset GetMsg(port)(a0)
  19. ReplayMsg          = -378  ; exec offset ReplayMsg(message)(a1)
  20. Forbid             = -132  ; exec offset Forbid()
  21. Open               = -30   ; dos offset  Open(name,accessMode)(D1/D2)
  22. Close              = -36   ; dos offset  Close(file)(D1)
  23. Write              = -48   ; dos offset  Write(file,buffer,length)(d1/d2/d3)
  24. OutPut             = -60   ; dos offset  OutPut()
  25. Lock               = -84   ; dos offset! Lock(name,mode)(d1,d2)
  26. UnLock             = -90   ; dos offset! UnLock(lock)(d1)
  27. Examine            = -102  ; dos offset! Examine(Lock,InfoBlock)(d1,d2)
  28. CurrentDir         = -126  ; dos offset  CurrentDir(lock)(d1)
  29. ParentDir          = -210  ; dos offset! ParentDir(lock)(d1)
  30. Execute            = -222  ; dos offset  Execute(string,file,file)(D1/D2/D3)
  31. GetDiskObject      = -78   ; icon offset GetDiskObject(name)(a0)
  32. FindToolType       = -96   ; icon offset FindToolType(toolTypeArray,typeName)(A0/A1)
  33. FreeDiskObject     = -90   ; icon offset FreeDiskObject(diskobj)(a0)
  34. Mode_old           = 1005  ;
  35. Mode_new           = 1006  ;
  36. Access_read        = -2
  37.  
  38.                    move.l sp,Initial_SP  ; Salva stackpointer
  39.                    move.l a0,Filename    ; CLI=salva davvero indirizzo arg.
  40.                    sub.l  #1,d0          ; Decrementa lunghezza di uno
  41.                    add.l  d0,a0          ; Somma lunghezza ad indirizzo
  42.                    move.b #0,(a0)        ; Azzera ultimo byte (CLI=0A)
  43.                    move.l #0,RetCode     ; Azzera Returncode
  44.  
  45. START:             move.l ExecBase,a6
  46.                    suba.l a1,a1          ; Indirizzo di questo task
  47.                    jsr    FindTask(a6)                
  48.                    move.l d0,a4          ; Salva struttura in a4
  49.                    tst.l  $ac(a4)        ; CLI or WB ?
  50.                    bne    CliStart
  51.  
  52. ; ** Questo vale solo quando si parte da Workbench
  53.  
  54.                    move.l #49,RetCode    ; Assegna Returncode
  55.                    lea    $5c(a4),a0     ; Messaggio WBench
  56.                    jsr    WaitPort(a6)   ; Attendi
  57.                    jsr    GetMsg(a6)     ; Carica messaggio
  58.                    move.l d0,Message     ; Salva puntatore a WBMessage
  59.                    beq    Slut           ; Errore!
  60.  
  61.                    move.l #48,RetCode    ; Fissa ReturnCode
  62.                    move.l Message,a0     ; Puntatore a WBMessage
  63.                    move.l $24(a0),a0     ; Lista argomenti
  64.                    beq    Slut2          ; Nessun argomento
  65.  
  66. CliStart:
  67.  
  68. ; **  Apre icon.library
  69.  
  70.                    move.l #47,RetCode      ; Assegna Returncode
  71.                    lea    Iconname(pc),a1  ; Carica indirizzo di IconName in a1
  72.                    clr.l  d0               ; Tutte le versioni
  73.                    jsr    OpenLibrary(a6)  ; Apre IconLibrary
  74.                    move.l d0,Iconbase      ; Salva Iconbase
  75.                    beq    Error1           ; Salta su errore!
  76.  
  77. ; ** Apre dos.library
  78.  
  79.                    move.l #46,RetCode      ; Assegna ReturnCode
  80.                    lea    Dosname(pc),a1   ; Indirizzo di DosName in a1
  81.                    clr.l  d0               ; Tutte le DosVersion
  82.                    jsr    OpenLibrary(a6)  ; Apre doslibrary
  83.                    move.l d0,DosBase       ; Salva Dosbase
  84.                    beq    Error2           ; Salta su errore!
  85.  
  86.                    jsr    PointTOCLI       ; Ricava puntatore CLI
  87.  
  88.                    tst.l  Message          ; Se partuto da CLI
  89.                    beq    InFileOpen       ; Salta su FileOpens
  90.  
  91. ; ** Apre Directory corrente
  92.  
  93.                    move.l #45,RetCode      ; Assegna Returncode
  94.                    move.l Message,a0       ; Puntatore a WBMessage sm_ArgList
  95.                    move.l $24(a0),a0       ; Sposta puntatore a wa_Lock
  96.                    beq    Error3           ; Errore!
  97.  
  98.                    move.l (a0),d1          ; D1 => Lock
  99.                    move.l DosBase,a6
  100.                    jsr    CurrentDir(a6)   ; Lock Current Dir
  101.  
  102. ; ** Legge diskobject (.info file)
  103.  
  104.                    move.l #44,RetCode      ; Assegna ReturnCode
  105.                    move.l Message,a0
  106.                    move.l $24(a0),a0
  107.                    move.l 4(a0),a0         ; Sposta puntatore a wa_Name
  108.                    move.l a0,Filename
  109.                    move.l Iconbase,a6
  110.                    jsr    GetDiskObject(a6) ; Legge diskobject
  111.                    move.l d0,Diskobj        ; Salva diskobject
  112.                    beq    Error3            ; Errore!
  113.                    move.l d0,a1
  114.                    move.l $36(a1),a1        ; Puntatore a ToolType Array
  115.                    move.l a1,ToolTypeArray  ; Salva puntatore
  116.  
  117. ; ** Legge argomento da tool icon (tooltype)
  118.  
  119.                    move.l Iconbase,a6
  120.                    move.l ToolTypeArray,a0
  121.                    move.l #typeName1,a1
  122.                    jsr    FindToolType(a6)
  123.                    move.l d0,Inname
  124.  
  125.                    move.l ToolTypeArray,a0
  126.                    move.l #typeName2,a1
  127.                    jsr    FindToolType(a6)
  128.                    move.l d0,Outname
  129.  
  130. ; ** Apre outfile
  131.  
  132.                    move.l #43,RetCode       ; Assegna Returncode
  133.                    move.l DosBase,a6        ; Carica dosbase
  134.                    move.l Outname,d1        ; Leggi filename
  135.                    move.l #Mode_new,d2      ; 1006=Nuovo File: 1005=Esistente
  136.                    jsr    Open(a6)          ; Apre file
  137.                    move.l d0,Outhandle      ; Salva filehandler
  138.                    beq    Error3            ; Salta per errore
  139.  
  140. ; ** Apre file di lettura
  141.  
  142. InFileOpen:
  143.                    move.l #42,RetCode       ; Assegna Returncode
  144.                    move.l Filename,d1       ; Carica filename
  145.                    tst.l  Message           ; Verifica se da WB o da CLI?
  146.                    beq.s  InOpLab           ; Salata se da CLI
  147.                    move.l Inname,d1         ; Carica filename
  148. InOpLab:           move   #Mode_old,d2      ; 1005=Existing file : 1006=NewFile
  149.                    move.l DosBase,a6        ; Carica dosbase
  150.                    jsr    Open(a6)          ; Apre file
  151.                    move.l d0,InHandle       ; Salva filehandler
  152.                    bne    BldPath           ; Salta se non ci sono errori
  153.  
  154.                    tst.l  Message           ; Verifica se da WB o da CLI?
  155.                    bne.s  Err               ; Salta se da Woorkbench
  156.                    move.l CLIPoint,d1
  157.                    move.l #Textfld,d2
  158.                    move.l #84,d3
  159.                    jsr    Write(a6)
  160. Err:               bra    Error4
  161.  
  162.  
  163. ; ** Legge e costruisce pathway
  164.  
  165. BldPath:           jsr    GetPath            ; Costruisce path
  166.  
  167. ; ** Chiama Execute (funzione DOS)
  168.  
  169.                    move.l #0,RetCode         ; Azzera Returncode
  170.                    move.l CLIPoint,d3
  171.  
  172.                    tst.l  Message            ; Verifica se da WB o da CLI
  173.                    beq.s  Exlabel            ; Termina se da CLI
  174.  
  175.                    move.l Outhandle,d3       ; Legge handler del file
  176. Exlabel:           move.l PathStart,d1       ; Legge puntatore della stringa
  177.                    move.l InHandle,d2        ; Legge handler del file
  178.                    jsr    Execute(a6)        ; Esegue un file script (dos)
  179.  
  180. ; ** Close files
  181.  
  182. Cleanup1:          move.l InHandle,d1
  183.                    jsr    Close(a6)
  184.  
  185. Error4:            tst.l  Message            ; Verifica se da Wb o da CLI
  186.                    beq.s  temp               ; Salta a fine se da CLI
  187.  
  188.                    move.l Outhandle,d1
  189.                    jsr    Close(a6)
  190.  
  191. Error3:            move.l Iconbase,a6        ; Carica Iconbase
  192.                    move.l Diskobj,a0         ; Legge struttura diskobject
  193.                    jsr    FreeDiskObject(a6) ; Free Diskobject
  194.  
  195. temp:              move.l DosBase,a1         ; Carica Dosbase
  196.                    move.l ExecBase,a6
  197.                    jsr    CloseLibrary(a6)   ; Chiuse Doslibrary:
  198.  
  199. Error2:            move.l Iconbase,a1        ; Carica IconBase
  200.                    move.l ExecBase,a6
  201.                    jsr    CloseLibrary(a6)   ; Chiudi Iconlibrary
  202.  
  203.  
  204. Error1:            tst.l  Message            ; Verifica se da WB o da CLI
  205.                    beq.s  Slut               ; Salta a fine se da CLI
  206. Slut2:             jsr    Forbid(a6)
  207.                    move.l Message,a1
  208.                    jsr    ReplayMsg(a6)      ; Elimina struttura reply
  209.  
  210. Slut:              move.l Initial_SP,sp      ; Carica blocco partenza
  211.                    clr.l  d0
  212.                    move.l RetCode,d0         ; Scrive returncode in D0
  213.                    rts
  214.  
  215. ; **** Dati di sistema
  216.  
  217. Initial_SP:        dc.l   0
  218. RetCode:           dc.l   0
  219. Iconbase:          dc.l   0
  220. DosBase:           dc.l   0
  221. InHandle:          dc.l   0
  222. Outhandle:         dc.l   0
  223. Message:           dc.l   0
  224. Diskobj:           dc.l   0
  225. CLIPoint:          dc.l   0
  226. Filename:          dc.l   0
  227. NewLock:           dc.l   0
  228. ParLock:           dc.l   0
  229. Inname:            dc.l   0
  230. Outname:           dc.l   0
  231. PathStart:         dc.l   0
  232. Dosname:           dc.b   'dos.library',0
  233.                    cnop   0,4
  234. Iconname:          dc.b   'icon.library',0
  235.                    cnop   0,4
  236. TempNamn:          dcb.b  32,0
  237.                    cnop   0,4
  238. Path:              dcb.b  255,0
  239.                    cnop   0,4
  240. typeName1:         dc.b   "FILENAME",0,0
  241.                    cnop   0,4
  242. typeName2:         dc.b   "WINDOW",0,0
  243.                    cnop   0,4
  244. Textfld:           dc.b   27,"[33mNewEx Version 1.1 by Kjell Cederfeldt",13,10,10
  245.                    dc.b   "No file name or file not found!",27,"[31m",13,10,10
  246.                    cnop   0,4
  247. ToolTypeArray:     dc.l   0
  248. IconText:          dc.l   0
  249. FileInfoBlock:     dcb.b  260,0
  250.                    cnop   0,4
  251.  
  252. ; ReturnCode 47 = icon.library not open
  253. ; ReturnCode 46 = dos.library  not open
  254. ; ReturnCode 45 = currentdir not lock
  255. ; ReturnCode 44 = diskobjekt not found
  256. ; ReturnCode 43 = outfile (device) not found
  257. ; ReturnCode 42 = infile (device) not found
  258.  
  259. ; *****  S U B R O U T I N E S *****
  260.  
  261. PointTOCLI:
  262.  
  263. ; Funzione di output sulla finestra CLI già aperta se esecuzione è da CLI
  264.  
  265.                    move.l DosBase,a6      ; Puntatore DOS.library
  266.                    jsr    OutPut(a6)      ; Legge puntatore di output Dos!
  267.                    move.l d1,CLIPoint     ; Salva puntatore
  268.                    rts
  269.  
  270. ;***************************************************************************
  271.  
  272. GetPath:
  273.                    move.l #Path,d2        ; Legge indirizzo di Path
  274.                    add.l  #253,d2         ; Sottrae 2
  275.                    move.l d2,PathStart    ; Legge indirizzo della pathstring
  276.  
  277.                    move.l DosBase,a6      ; Carica DOSBasc
  278.                    move.l #Filename,d1    ; Carica puntatore di nome file
  279.                    move.l Access_read,d2  ; Modo Solo lettura
  280.                    jsr    Lock(a6)        ; Bloccaggio
  281.                    tst.l  d0
  282.                    beq    EndLoop         ; File introvabile
  283.                    move.l d0,NewLock      ; Memorizza Lock
  284.  
  285. MainLoop:          move.l NewLock,d1        ; Legge lock
  286.                    move.l #FileInfoBlock,d2 ; Legge indirizzo nel blocco
  287.                    jsr    Examine(a6)       ; Legge fileinfo
  288.                    tst.l  d0
  289.                    beq    EndLoop
  290.  
  291.                    move.l #FileInfoBlock,d2
  292.                    add.l  #8,d2           ; Aggiunge offset all'indirizzo
  293.  
  294.                    clr.l  d0              ; Azzera contatore
  295.                    move.l d2,a0           ; Sposta filepointer in A0
  296.                    move.l #TempNamn,a1    ; Sposta pathpointer in A1
  297. Loop:              move.b (a0)+,(a1)+     ; Sposta valore A0 => A1
  298.                    add.l  #1,d0           ; Decrementa contatore
  299.  
  300.                    tst.b  (a0)            ; Fine nome (0 di termine)?
  301.                    bne.s  Loop            ; No: cicla 
  302.  
  303.                    move.b #47,(a1)+       ; Aggiunge '/'
  304.                    add.l  #1,d0           ; Decrementa contatore
  305.  
  306.                    move.l PathStart,d2    ; Legge path di partenza
  307.                    move.l d2,a0
  308.  
  309. Loop2:             move.b -(a1),-(a0)     ; Salva struttura di path
  310.                    sub.l  #1,d0           ; Incrementa contatore
  311.                    bne.s  Loop2
  312.  
  313.                    move.l a0,PathStart    ; Salva pathstart
  314.  
  315.                    move.l NewLock,d1      ; Legge Lock
  316.                    jsr    ParentDir(a6)   ; Vai a DIR parente
  317.                    move.l d0,ParLock      ; Salva lock
  318.                    move.l NewLock,d1      ; Legge lock
  319.                    jsr    UnLock(a6)      ; Rilascia lock
  320.                    move.l ParLock,d0      ; Legge lock
  321.                    move.l d0,NewLock      ; Muove lock
  322.                    tst.l  d0              ; Siamo nella radice
  323.                    bne    MainLoop        ; Nessun salto
  324.  
  325.                    move.l PathStart,a1    ; Legge pathstart
  326. Kolon:             cmp.b  #47,(a1)+       ; Trovato prima '/'
  327.                    bne.s  Kolon
  328.                    move.b #58,-(a1)       ; Modifica in ':'
  329.  
  330.                    move.l PathStart,a1    ; Legge pathstart
  331.                    move.b #34,-(a1)       ; somma '"'
  332.                    move.b #32,-(a1)       ; somma ' '
  333.                    move.b #68,-(a1)       ; somma 'D'
  334.                    move.b #67,-(a1)       ; somma 'C'
  335.                    move.l a1,PathStart    ; salva niova partenza         
  336.                    move.l #Path,a1
  337.                    add.l  #253,a1
  338.                    move.b #34,(a1)
  339.  
  340. EndLoop:           rts
  341.                    end
  342.